package com.qf.service.impl;

/*
 *  @author Administrator
 *  @version V1.0
 *  @Project banwoqiche
 *  @Package com.qf.service
 *  @Description
 *  @Date2022/3/29 0029 19:29
 */

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.bean.member.Member;
import com.qf.bean.member.MemberFav;
import com.qf.dto.UserDto;
import com.qf.mapper.MemberMapper;
import com.qf.service.MemberService;
import com.qf.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class MemberServiceImpl implements MemberService {
    private MemberMapper memberMapper;

    @Autowired
    public void setMemberMapper(MemberMapper memberMapper) {
        this.memberMapper = memberMapper;
    }

    @Override
    public PageInfo<Member> findAll(Integer page,Integer limit) {
//        SecurityContextHolder.getContext().getAuthentication().getPrincipal()
        UserDto loginUser = SecurityUtils.getLoginUser();
        System.err.println(loginUser);
//        Assert.notNull(loginUser,()->{
//            throw new MyException("请登录", ResultCode.LOGIN_NOT);
//        });
        PageHelper.startPage(page, limit);
        List<Member> memberList = memberMapper.findAll();
        PageInfo<Member> pageInfo = new PageInfo<>(memberList);
        pageInfo.setTotal(memberList.size());
        pageInfo.setPageNum(page);
        return pageInfo;
    }

    @Override
    public List<MemberFav> findAllFavAirticle(Integer memberId) {
        return memberMapper.findAllFavAirticle(memberId);
    }

    @Override
    public List<MemberFav> findAllFavActivity(Integer memberId) {
        return memberMapper.findAllFavActivity(memberId);
    }

    @Override
    public List<MemberFav> findAllFavCar(Integer memberId) {
        return memberMapper.findAllFavCar(memberId);
    }

    @Override
    public List<MemberFav> findAllTag(Integer memberId) {
        return memberMapper.findAllTag(memberId);
    }
}
